package com.jx.gocomtask.webservice.repository;

import com.jx.gocomtask.webservice.entity.ExtTaskMessageHistory;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by LWD on 2017/8/22.
 */
public interface ExtTaskMessageHistoryRepository
        extends PagingAndSortingRepository<ExtTaskMessageHistory,Long>,JpaSpecificationExecutor<ExtTaskMessageHistory> {
	List<ExtTaskMessageHistory> findByTodoIdAndMessageIdNotNull(long todoId);
	
	//@Query(value = "SELECT  e.todoId, DISTINCT e.messageId FROM  ExtTaskMessageHistory  e  WHERE e.todoId IN (?1) AND e.messageId IS NOT NULL", nativeQuery = true)
	@Query(value = "SELECT  DISTINCT(e.message_id) , e.todo_id FROM  Ext_Task_Message_History  e  WHERE e.todo_Id IN (?1) AND e.message_Id IS NOT NULL", nativeQuery = true)
	List<Object[]> selectOneMessageId(List<Long> ids);
	
	@Modifying      
	@Transactional
	@Query(value = "UPDATE ExtTaskMessageHistory  e SET e.messageId = ?1  WHERE e.todoId = ?2")
	public void updateTodoHistory(Long messageId,Long todoId);
	
}
